package com.boyi.center.controller.impl;

import com.boyi.center.controller.BaseController;
import com.boyi.center.service.BaseService;
import com.boyi.shared.common.Result;
import com.boyi.validator.AddGroup;
import com.boyi.validator.UpdateGroup;
import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author tingwen
 * @date 2017/3/28 21:06
 * @description
 */
@Controller
public abstract class BaseControllerImpl<T> implements BaseController<T> {
    @Autowired
    private BaseService<T> baseService;

    @PostMapping
    @ResponseBody
    @Override
    public Result<List<T>> save(@Validated({AddGroup.class}) T entity) {
        return baseService.save(entity);
    }

    @DeleteMapping
    @ResponseBody
    @Override
    public Result<List<T>> delete(T entity) {
        return baseService.delete(entity);
    }

    @PutMapping
    @ResponseBody
    @Override
    public Result<List<T>> updateNotNull(@Validated(UpdateGroup.class) T entity) {
        return baseService.updateNotNull(entity);
    }

    @GetMapping
    @ResponseBody
    @Override
    public Result<List<T>> select(T entity) {
        return baseService.select(entity);
    }

}
